home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d18 / opbonus.arc / PHMOD.ARC / PHMOD.PAS < prev   
Pascal/Delphi Source File  |  1991-03-20  |  3KB  |  116 lines

  1. {************************************************************************
  2.   Patches POPHELP.EXE to use a new default database.  This is simpler and
  3.   faster than changing and recompiling the source code (when the only change
  4.   is to refer to a different default database).
  5.  
  6.   Usage: PHMOD NewHelpFileName [options]
  7.      /N PgmName  Program name [default = POPHELP.EXE]
  8.      /?          Display help
  9.  
  10.   Written 5/3/90, Terry Hughes, TurboPower Software
  11.   CompuServe ID [72077,1450]
  12. ************************************************************************}
  13.  
  14. {$R-,S-,V-,F+,A-,I-}
  15.  
  16. program PhMod;
  17.   {-Changes the default database in POPHELP.EXE}
  18.  
  19. uses
  20.   Dos,
  21.   OpString,
  22.   OpClone;
  23.  
  24. const
  25.   {Installation area}
  26.   DBName       : PathStr = 'OPRO.HLP';  {Default help file to load}
  27.   HeapOverHead : Word = $1300;          {Total heap overhead}
  28.   Swap1Name  : String[65] = 'POPHELP.SW1'; {Length limited by OPSWAP1}
  29.  
  30.   PgmName : PathStr = 'POPHELP.EXE';
  31.   CopyRightLine = 'PHMOD 1.00 Copyright TurboPower Software 1990.';
  32.  
  33. var
  34.   C : Cloner;
  35.   DBOfs : LongInt;
  36.   Status : Word;
  37.  
  38. procedure WriteHelp;
  39.   {-Display help screen and halt}
  40. begin
  41.   WriteLn('Usage: PHMOD NewHelpFileName [options]'^M);
  42.   WriteLn('  /N PgmName  Program name [default = POPHELP.EXE]');
  43.   WriteLn('  /?          Display help'^M^J);
  44.   Halt(1);
  45. end;
  46.  
  47. procedure Abort(Msg : String);
  48. begin
  49.   WriteLn(Msg,^M^J);
  50.   Halt(1);
  51. end;
  52.  
  53. procedure ParseCommandLine;
  54.   {-Gets command line options and sets various parameters}
  55. var
  56.   Code : Word;
  57.   Param : String;
  58.   Cnt : Word;
  59.   ComNum : Word;
  60.  
  61. begin
  62.   {Scan command line}
  63.   if ParamCount = 0 then
  64.     WriteHelp;
  65.  
  66.   Cnt := 1;
  67.   Param := ParamStr(Cnt);
  68.  
  69.   while Cnt <= ParamCount do begin
  70.     case Param[1] of
  71.       '/', '-' :
  72.         if Length(Param) <> 2 then
  73.           Abort('Invalid parameter: '+Param)
  74.         else
  75.           case Upcase(Param[2]) of
  76.             'N' : begin
  77.                     Inc(Cnt);
  78.                     PgmName := StUpcase(ParamStr(Cnt));
  79.                   end;
  80.             '?' : WriteHelp;
  81.           else
  82.             Abort('Invalid parameter: '+Param);
  83.           end;
  84.       else
  85.         DBName := StUpCase(ParamStr(Cnt));
  86.     end;
  87.     Inc(Cnt);
  88.     Param := ParamStr(Cnt);
  89.   end;
  90. end;
  91.  
  92. begin
  93.   {Startup}
  94.   WriteLn(CopyRightLine,^M^J);
  95.   ParseCommandLine;
  96.   {Open the file and find the id string}
  97.   if not C.Init(PgmName, UpdateDate) then
  98.     Abort('Unable to modify '+PgmName);
  99.   if not C.FindDefaultsEnd(Swap1Name, SizeOf(Swap1Name), 0) then
  100.     Abort('Unable to find ID string in '+PgmName);
  101.   WriteLn('Opening '+PgmName+'...');
  102.  
  103.   {Adjust DBOfs to point to DBName}
  104.   DBOfs := C.GetPos - SizeOf(DBName) - 2;
  105.  
  106.   {Store the new database name}
  107.   WriteLn('Storing '+DBName+'...');
  108.   C.StoreDefaults(DBOfs, DBName, SizeOf(DBName));
  109.   Status := C.GetLastError;
  110.   if Status <> 0 then
  111.     Abort('Unable to write modifications to '+PgmName + ' ' + Long2Str(Status));
  112.   WriteLn(PgmName+' successfully updated'^M^J);
  113.   C.Done;
  114. end.
  115.  
  116.